1
|
|
|
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1'; |
2
|
|
|
import {offsetToTimezone} from '../helpers/time'; |
3
|
|
|
import ClosePollFormCard from './ClosePollFormCard'; |
4
|
|
|
|
5
|
|
|
export default class ScheduleClosePollFormCard extends ClosePollFormCard { |
6
|
|
|
create(): chatV1.Schema$GoogleAppsCardV1Card { |
7
|
|
|
this.buildHeader(); |
8
|
|
|
if (this.state.closedTime) { |
9
|
|
|
this.buildCurrentScheduleInfo(); |
10
|
|
|
} |
11
|
|
|
this.buildAutoCloseSection(); |
12
|
|
|
this.buildButtons(); |
13
|
|
|
this.buildSections(); |
14
|
|
|
return this.card; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
buildHeader() { |
18
|
|
|
this.card.header = { |
19
|
|
|
'title': 'Schedule Close Poll', |
20
|
|
|
'subtitle': 'You can schedule the poll to close here.', |
21
|
|
|
'imageUrl': '', |
22
|
|
|
'imageType': 'CIRCLE', |
23
|
|
|
}; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
buildButtons() { |
27
|
|
|
let scheduleButtonText = 'Create Schedule Close'; |
28
|
|
|
if (this.state.closedTime) { |
29
|
|
|
scheduleButtonText = 'Edit Schedule Close'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
this.addSectionWidget({ |
33
|
|
|
'buttonList': { |
34
|
|
|
'buttons': [this.createButton(scheduleButtonText, 'schedule_close_poll')], |
35
|
|
|
}, |
36
|
|
|
}); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
buildAutoCloseSection() { |
40
|
|
|
const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = []; |
41
|
|
|
const timezone = offsetToTimezone(this.timezone.offset); |
42
|
|
|
let scheduleTime = Date.now() + 18000000; |
43
|
|
|
if (this.state.closedTime) { |
44
|
|
|
scheduleTime = this.state.closedTime; |
45
|
|
|
} |
46
|
|
|
scheduleTime += this.timezone.offset; |
47
|
|
|
widgets.push( |
48
|
|
|
{ |
49
|
|
|
'dateTimePicker': { |
50
|
|
|
'label': 'Close schedule time ' + timezone, |
51
|
|
|
'name': 'close_schedule_time', |
52
|
|
|
'type': 'DATE_AND_TIME', |
53
|
|
|
'valueMsEpoch': scheduleTime.toString(), |
54
|
|
|
}, |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
widgets.push( |
58
|
|
|
{ |
59
|
|
|
'decoratedText': { |
60
|
|
|
'text': 'Auto mention <b>@all</b> on 5 minutes before poll closed', |
61
|
|
|
'bottomLabel': 'This is to ensure that other users do not forget to vote before the poll is closed.', |
62
|
|
|
'switchControl': { |
63
|
|
|
'controlType': 'SWITCH', |
64
|
|
|
'name': 'auto_mention', |
65
|
|
|
'value': '1', |
66
|
|
|
'selected': true, |
67
|
|
|
}, |
68
|
|
|
}, |
69
|
|
|
}); |
70
|
|
|
this.card.sections!.push({ |
71
|
|
|
widgets, |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|